import java.util.Random;
import java.util.Scanner;

public class NGuessNumber {
    /**
     * 返回四个0-10的数
     * @return
     */
    public int[] generateAnswer(){
        Random random = new Random();
        int [] comp = new int[4];
        for (int i = 0; i < 4;) {
            int computer= random.nextInt(10);
            int b =0;
            for (int j = 0; j <4 ; j++) {
                if (computer ==comp[j]){
                    b=1;
                    break;
                }
            }
            if (b==0){
                comp[i]=computer;
                i++;
            }
            }

        return comp;
    }

    /**
     * 接受数字方法
     */
    public int[] getPlayerInput(){
        int [] person = new int[4];
        Scanner scanner = new Scanner(System.in);
        for (int i = 0; i < 4; i++) {
            person[i]=scanner.nextInt();
        }
        return person;
    }

    /**
     * 判断结果方法
     * @param play
     * @return
     */
    public boolean iswin(int []play){
        if (play[0]==4){
            return true;
        }
        return false;
    }

    /**
     * 输出结果的方法
     * @param computer
     * @param person
     * @return
     */
    public int[] compareGuessAnswer(int [] computer,int [] person){
        int key [] = new int[2];
        int a =0;
        int b =0;
        for (int i = 0; i < 4; i++) {
            for (int j = 0; j < 4; j++) {
                if (computer[i]==person[j]){
                    if (i==j) a++;
                    else b++;
                }
            }
        }
        key[0]=a;
        key[1]=b;
        return key;
    }

    public static void main(String[] args) {
        NGuessNumber number = new NGuessNumber();
        int computer[] = number.generateAnswer();
        Scanner scanner = new Scanner(System.in);
        String YN = null;
        boolean play=true;
        while (play){
        boolean iswin=false;
        System.out.println("输入数字");
        while(!iswin){
        int person[] = number.getPlayerInput();
        int com []= number.compareGuessAnswer(computer,person);
        iswin=number.iswin(com);
        if (!iswin){
            System.out.println(com[0]+" A"+" "+com[1]+" B");
        }else
        {
            System.out.println("恭喜您答对了");
        }
        }
        while (true){
            System.out.println("是否继续游戏 Y/N");
            YN = scanner.next();
            if (YN.equals("Y")||YN.equals("y"))break;
            else if(YN.equals("N")||YN.equals("n")){
                play=false;
                break;
            }else{
                System.out.println("输入错误，重新输入");
            }
    }
    }
    }
}